﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

namespace ENG.PSSAirbusSoundExtender
{
  static class Program
  {
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main()
    {
      Gma.UserActivityMonitor.HookManager.MouseUp += new MouseEventHandler(HookManager_MouseUp);
      Gma.UserActivityMonitor.HookManager.KeyDownOnce += new KeyEventHandler(HookManager_KeyDownOnce);
      Gma.UserActivityMonitor.HookManager.KeyUp += new KeyEventHandler(HookManager_KeyUp);

      Application.EnableVisualStyles();
      Application.SetCompatibleTextRenderingDefault(false);
      Application.Run(new FrmMain());
    }

    static void HookManager_KeyUp(object sender, KeyEventArgs e)
    {
      if (e.KeyCode == Keys.NumPad5)
      {
        IsInOverhead = false;
        Console.WriteLine("Numpad5 UP");
        if (OverheadChange != null)
          OverheadChange(IsInOverhead);
      }
    }

    static void HookManager_KeyDownOnce(object sender, KeyEventArgs e)
    {
      if (e.KeyCode == Keys.NumPad5)
      {
        IsInOverhead = true;
        Console.WriteLine("Numpad5 DOWN");
        if (OverheadChange != null)
          OverheadChange(IsInOverhead);
      }
    }

    private static bool _IsInCalibration = false;
    public static bool IsInCalibration
    {
      get
      {
        return _IsInCalibration;
      }
      set
      {
        _IsInCalibration = value;
        Console.WriteLine("IsInCalibration: " + value);
      }
    }
    private static bool IsInOverhead = false;
    public delegate void ClickHandler(System.Drawing.Point point);
    public static event ClickHandler OverheadClick;
    public static event ClickHandler CalibrationClick;
    public delegate void OverheadChangeHandler(bool isNowOverhead);
    public static event OverheadChangeHandler OverheadChange;

    static void HookManager_MouseUp(object sender, MouseEventArgs e)
    {
      if (IsInCalibration)
      {
        Console.WriteLine("Calibration click");
        if (CalibrationClick != null)
          CalibrationClick(e.Location);
      }
      else if (IsInOverhead)
      {
        if (OverheadClick != null)
        {
          Console.WriteLine("Overhead click");
          OverheadClick(e.Location);
        }
      }
    }

  }
}
